package com.example.vaccine.controller;

import com.example.vaccine.VO.PageVO;
import com.example.vaccine.VO.ResultVO;
import com.example.vaccine.entity.CheckRecords;
import com.example.vaccine.service.CheckRecordsService;
import com.example.vaccine.util.ResultVOUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>前端控制器</p>
 */
@RestController
@RequestMapping("/checkRecords")
@Tag(name = "核查记录管理", description = "CheckRecordsController")
public class CheckRecordsController {

    @Autowired
    private CheckRecordsService checkRecordsService;

    /**
     * 分页查询核查记录（可选疫苗编号筛选）
     */
    @Operation(summary = "分页查询核查记录", description = "可根据疫苗编号筛选")
    @GetMapping("/searchRecords")
    public ResultVO searchRecords(
            @Parameter(description = "当前页码", required = true) @RequestParam Integer page,
            @Parameter(description = "每页条数", required = true) @RequestParam Integer size,
            @Parameter(description = "疫苗编号（可选）") @RequestParam(required = false) String vaccineNumbering
    ) {
        PageVO pageVO = checkRecordsService.searchRecords(vaccineNumbering, page, size);
        return ResultVOUtil.success(pageVO);
    }

    /**
     * 根据 ID 获取核查记录详情
     */
    @Operation(summary = "获取核查记录详情", description = "根据主键 ID 获取记录")
    @GetMapping("/detail/{id}")
    public ResultVO getDetail(
            @Parameter(description = "核查记录 ID", required = true) @PathVariable Long id) {
        CheckRecords record = checkRecordsService.getById(id);
        if (record == null) {
            return ResultVOUtil.fail();
        }
        return ResultVOUtil.success(record);
    }
}
